package com.yyysj.system.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyysj.system.domain.dto.CommentDTO;
import com.yyysj.system.domain.po.Comment;
import com.yyysj.system.domain.vo.CommentVO;
import com.yyysj.system.mapper.CommentMapper;
import com.yyysj.system.service.ICommentService;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@RequiredArgsConstructor
public class CommentServiceImpl implements ICommentService {

    private final CommentMapper commentMapper;

    @Override
    public CommentVO getCommentList(CommentDTO commentDTO) {
        PageHelper.startPage(commentDTO.getPageNum(), commentDTO.getPageSize());
        List<Comment> commentList = commentMapper.selectCommentList(commentDTO.getCommentId(), commentDTO.getPostId(), commentDTO.getNickName());
        Page<Comment> page = (Page<Comment>) commentList;
        PageInfo<Comment> pageInfo = new PageInfo<>(page);
        return new CommentVO(commentList, pageInfo.getTotal());
    }

    @Override
    public boolean updateCommentStatus(Long commentId, Integer status) {
        return commentMapper.updateCommentStatus(commentId, status) > 0;
    }

    @Override
    public boolean deleteComment(Long commentId) {
        return commentMapper.deleteComment(commentId) > 0;
    }
}
